define(["jquery", "bootstrap", "backend", "table", "form"], function (
  $,
  undefined,
  Backend,
  Table,
  Form
) {
  var Controller = {
    index: function () {
      // 初始化表格参数配置
      Table.api.init({
        extend: {
          index_url: "business/privatesea/index" + location.search,
          add_url: "business/privatesea/add",
          edit_url: "business/privatesea/edit",
          del_url: "business/privatesea/del",
          info_url: "business/info/index",
          table: "business",
        },
      });

      var table = $("#table");

      // 初始化表格
      table.bootstrapTable({
        url: $.fn.bootstrapTable.defaults.extend.index_url,
        pk: "id",
        sortName: "id",
        fixedColumns: true,
        fixedRightNumber: 1,
        columns: [
          [
            { checkbox: true },
            { field: "mobile", title: __("Mobile"), operate: "LIKE" },
            { field: "nickname", title: __("Nickname"), operate: "LIKE" },
            {
              field: "avatar",
              title: __("Avatar"),
              operate: "LIKE",
              events: Table.api.events.image,
              formatter: Table.api.formatter.image,
              operate:false
            },
            {
              field: "gender",
              title: __("Gender"),
              searchList: {
                0: __("Gender 0"),
                1: __("Gender 1"),
                2: __("Gender 2"),
              },
              formatter: Table.api.formatter.normal,
            },
            { field: "source.name", title: __("BusinessSource") },
            {
              field: "deal",
              title: __("BusinessDeal"),
              searchList: { 0: __("BusinessDeal 0"), 1: __("BusinessDeal 1") },
              formatter: Table.api.formatter.normal,
            },
            { field: "provinces.name", title: __("Province"), operate: "LIKE" },
            { field: "citys.name", title: __("City"), operate: "LIKE" },
            { field: "districts.name", title: __("District"), operate: "LIKE" },
            { field: "money", title: __("Money"), operate: "BETWEEN" },
            {
              field: "email",
              title: __("Email"),
              operate: "LIKE",
              table: table,
              class: "autocontent",
              formatter: Table.api.formatter.content,
            },
            {
              field: "auth",
              title: __("BusinessAuth"),
              searchList: { 0: __("BusinessAuth 0"), 1: __("BusinessAuth 1") },
              formatter: Table.api.formatter.normal,
            },
            {
              field: "poster",
              title: __("BusinessPoster"),
              operate: "LIKE",
              events: Table.api.events.image,
              formatter: Table.api.formatter.image,
            },
            {
              field: "createtime",
              title: __("Createtime"),
              operate: "RANGE",
              addclass: "datetimerange",
              autocomplete: false,
              formatter: Table.api.formatter.datetime,
            },
            { field: "parent.nickname", title: __("BusinessParent") },
            { field: "admin.nickname", title: __("BusinessAdmin") },
            {
              field: "operate",
              title: __("Operate"),
              table: table,
              events: Table.api.events.operate,
              formatter: Table.api.formatter.operate,
              buttons: [
                {
                  name: "info",
                  title: "客户详情",
                  classname: "btn btn-xs btn-success btn-dialog",
                  icon: "fa fa-eye",
                  extend:
                    "data-toggle='tooltip' data-area= '[\"80%\", \"100%\"]'",
                  url: $.fn.bootstrapTable.defaults.extend.info_url,
                },
              ],
            },
          ],
        ],
      });

      // 为表格绑定事件
      Table.api.bindevent(table);
    },
    add: function () {
      // Fast.api.query()
      Controller.api.bindevent();
    },
    edit: function () {
      Controller.api.bindevent();
    },
    api: {
      bindevent: function () {
        Form.api.bindevent($("form[role=form]"));
      },
    },
  };
  return Controller;
});
